/** @QFi-template-author: wanghua
 ** @path view/vecspace/middleplatform/filemanagementpart/uploadFileAccessStat/uploadFileAccessStat_list.js  view/vecspace/middleplatform/filemanagementpart/uploadFileAccessStat/uploadFileAccessStat_list.ftl
 ** @url  api/view/middleplatform_uploadFileAccessStatHandler/list
 ** @class UploadFileAccessStatHandler.list()
 **/ 
var laytable;
var grid1;
var dkquery;
$(function() {
	laytable = layui.table;
	dkquery = $('#dkQueryPanel').dkQuery2();
	$('input').iCheck(); //$('#xxx').iCheck('check')	$('#xxx').iCheck('uncheck');
	$('input').on('ifChanged', function(event){ //checkbox或者radio输入框的 checked 或 disabled 状态改变了，由iCheck组件触发

	});

	initDataGrid();
	onBtnQueryClick();
});

$(window).load(function() {
	$("#btnDkQuery").focus(); //默认让查询按钮获取焦点，防止第一个获取的焦点是一个dkSelectTree类型的控件，会自动列出下拉列表。
});

function onBtnQueryClick(){
	var queryFields = dkquery.getQueryParams();
	reloadGridData(queryFields);
}

function onGetQueryParams(){
	var params = dkquery.getQueryParams();
	alert(JSON.stringify(params));
}

function initDataGrid(){
	grid1 = laytable.render({
		id:'maingrid1',
		elem:'#maingrid1',
		url: basePath+'api/base/middleplatform_uploadFileAccessStatHandler/getUploadFileAccessStatExList?js_plugin_type=laytable',
		delayLoad : true,		//true:在初始化表格时不加载数据
		cols: [[/*sort:false,fixed:false|'right',rowspan:1,colspan:1,render:function(row, rowindex, rows) */
			{type:'numbers', width:30},	/*行号*/
			{title:'日期', field:'logDate',type:'normal',width:80,align:'center'},
			{title:'5分钟刻度值', field:'minuteTick',type:'normal',width:80,align:'center'},
			{title:'服务器IP+端口', field:'fileServer',type:'normal',width:80,align:'center'},
			{title:'访问文件次数', field:'fileTimes',type:'normal',width:80,align:'center'},
			{title:'下载字节数（MB）', field:'fileBytes',type:'normal',width:80,align:'center'},

			{title: '操作', fixed:'right', width: 140 , unresize:true, allowHide: false,render: function (row){
				var idstr = "'"+row.id+"'";
				var name = "'" + row.logDate + "'";
				var html = '<a href="javascript:onItemInfoClick(' + idstr + ')" class="layui-btn layui-btn-primary layui-btn-mini grid_row_btn grid_row_info">详情</a>&nbsp;&nbsp;'+
					'<a href="javascript:onEditInfoClick(' + idstr + ')" class="layui-btn layui-btn-mini grid_row_btn grid_row_edit">编辑</a>&nbsp;&nbsp;'+
					'<a href="javascript:onDeleteClick(' + idstr + ','+ name+')" class="layui-btn layui-btn-danger layui-btn-mini grid_row_btn grid_row_del">删除</a>';
				return html;
			}}
		]],
		page : true,
		limit: 15,
		heightDiff : 0,
		even: true, //开启隔行背景，
		trackSelectedRow:true,//选中行高亮显示 .layui-table-row-active
		loading : false,//true：显示加载数据的loading
		onLoadData : function(data){//当从后台加载到数据的时候触发

		},
		onRowClick : function(index, row){//当点击一行的时候触发
			//console.log(index+':'+JSON.stringify(row));
		},
		onRowDblClick : function(index, row){//当双击一行的时候触发
			//console.log(index+':'+JSON.stringify(row));
		}
	});
}

function reloadGridData(queryFields){
	grid1.setRequestParam('queryFields', JSON.stringify(queryFields));
	grid1.changePage(1);
	grid1.reloadData();
}

function reloadCurrPageGridData(){
	grid1.reloadData();
}

function onGetGridData(gridData){
	if(gridData.hasError){
		alert(gridData.errorMessage);
		return false;
	}
}
var editDlgWidth = 715;
var editDlgHeight = 452;
var childDlg;

function onItemInfoClick(id){
	var url = basePath+"api/view/middleplatform_uploadFileAccessStatHandler/info?id="+id;
	var dlgparams = {title:'文件访问统计 详细信息', url: url, id:'info_TMS_UPLOAD_FILE_ACCESS_STAT', width:700, height: 400, modal:true};
	childDlg = dialogframe.openDialog(dlgparams);
}

function btnAddClick(){
	var url = basePath+'api/view/middleplatform_uploadFileAccessStatHandler/add';
	var dlgparams = {title:'添加 文件访问统计', url: url, id:'frm_addUploadFileAccessStat', width:editDlgWidth, height: editDlgHeight, modal:true};
	childDlg = dialogframe.openDialog(dlgparams);
	childDlg.bind('Close', function(){  //点击右上角关闭按钮时触发的事件，如果返回false，则终止关闭.
		//alert("before close");
		return true;
	});
	childDlg.bind('Closed', function(event){  //窗口关闭后触发的事件，event.type:'added' 或者空值,event.dataId,新增数据的Id
		if(event && 'added' == event.type){
			reloadCurrPageGridData();
		}
	});
}

function onEditInfoClick(id){
	var url = basePath+"api/view/middleplatform_uploadFileAccessStatHandler/edit?id="+id;
	var dlgparams = {title:'编辑 文件访问统计', url: url, id:'frm_editUploadFileAccessStat', width:editDlgWidth, height: editDlgHeight, modal:true};
	childDlg = dialogframe.openDialog(dlgparams);
	childDlg.bind('Close', function(){  //点击右上角关闭按钮时触发的事件，如果返回false，则终止关闭.
		//alert("before close");
		return true;
	});
	childDlg.bind('Closed', function(event){  //窗口关闭后触发的事件，	  event.type:'edited' 或者空值,event.dataId,新增数据的Id
		if(event && 'edited' == event.type){
			reloadCurrPageGridData();
		}
	});
}

function onDeleteClick(id,name){
	if(!name) name = '';
	var layer = layui.layer;
	layer.confirm('确认要删除['+name+']吗？', 
		{ btn: ['确认','取消'] }, 
		function(layerIdex){//确认
			var url = basePath + 'api/base/middleplatform_uploadFileAccessStatHandler/deleteUploadFileAccessStat';
			$.post(url,{'id':id},  function(data, textStatus, jqXHR){
				if(data.hasError){
					alert(data.errorMessage);
				}else{
					reloadCurrPageGridData();
				}
			});
			layer.close(layerIdex);
		}, 
		function(){//取消

		}
	);	
}

